#/bin/sh

alias curl='curl -stderr'
#Clearn Up temp files
\rm -f tmp* digest* *.html *.htm

echo "Money Flows: Selling-on-Strength and Buying-on-Weakness List"
curl -stderr "http://online.wsj.com/mdc/public/page/2_3022-mflppg-moneyflow.html?mod=mdc_leader" |egrep -o 'symbol=[A-Z]+' |cut -d'=' -f2 > SellingOnStrenghList
curl "http://online.wsj.com/mdc/public/page/2_3022-mfgppl-moneyflow.html?mod=mdc_leader" |egrep -o 'symbol=[A-Z]+' |cut -d'=' -f2 > BuyingOnWeaknessList

#Some special patterns, e.g., maxdowndays, largedownstocks etc.
./datawm.sh

echo "Reuters Lists"
./reuters.sh

#########################################################
echo "Download the latest up/down-grade to File"
export updownurl="http://moneycentral.msn.com/investor/calendar/ratings"

export today=`date +'%Y-%m-%d' |sed 's/-0/-/g'`
export day1=`date -d-1day +'%Y-%m-%d' |sed 's/-0/-/g'`
export day2=`date -d-2day +'%Y-%m-%d' |sed 's/-0/-/g'`
export day3=`date -d-3day +'%Y-%m-%d' |sed 's/-0/-/g'`
export day4=`date -d-4day +'%Y-%m-%d' |sed 's/-0/-/g'`

>Upgrade
curl -stderr "$updownurl/$today.asp?sel=0" |grep stock_quote |egrep -o  ">[A-Z]{1,4}<" |sed "s/>//g" |sed "s/<//g" >> Upgrade
curl -stderr "$updownurl/$day1.asp?sel=0" |grep stock_quote |egrep -o  ">[A-Z]{1,4}<" |sed "s/>//g" |sed "s/<//g" >> Upgrade
curl -stderr "$updownurl/$day2.asp?sel=0" |grep stock_quote |grep -o ">[A-Z]{1,4}<" |sed "s/>//g" |sed "s/<//g" >> Upgrade
curl -stderr "$updownurl/$day3.asp?sel=0" |grep stock_quote |grep -o ">[A-Z]{1,4}<" |sed "s/>//g" |sed "s/<//g" >> Upgrade
curl -stderr "$updownurl/$day4.asp?sel=0" |grep stock_quote |grep -o ">[A-Z]{1,4}<" |sed "s/>//g" |sed "s/<//g" >> Upgrade
>Downgrade
curl -stderr "$updownurl/$today.asp?sel=1" |grep stock_quote |egrep -o ">[A-Z]{1,4}<" |sed "s/>//g" |sed "s/<//g" >>Downgrade
curl -stderr "$updownurl/$day1.asp?sel=1" |grep stock_quote |egrep -o ">[A-Z]{1,4}<" |sed "s/>//g" |sed "s/<//g"  >>Downgrade
curl -stderr "$updownurl/$day2.asp?sel=1" |grep stock_quote |egrep -o ">[A-Z]{1,4}<" |sed "s/>//g" |sed "s/<//g"  >>Downgrade
curl -stderr "$updownurl/$day3.asp?sel=1" |grep stock_quote |egrep -o ">[A-Z]{1,4}<" |sed "s/>//g" |sed "s/<//g"  >>Downgrade
curl -stderr "$updownurl/$day4.asp?sel=1" |grep stock_quote |egrep -o ">[A-Z]{1,4}<" |sed "s/>//g" |sed "s/<//g"  >>Downgrade


echo "Insider Buy"
curl -stderr "http://www.insidercow.com/notLogin/buyByCompany.jsp" |egrep -o "company=[A-Z]+" |sort |uniq |cut -d'=' -f2 > InsiderList

echo "Institution Ownership Ups and Downs"
curl -stderr "http://moneycentral.msn.com/investor/finder/deluxestockscreen.aspx?query=Institutional+Ownership+Up+Last+Month" |sed 's/TR/\n/g' |egrep -o "Symbol=[A-Z]+" |cut -d= -f2 > InstitutionUpList
curl -stderr "http://moneycentral.msn.com/investor/finder/deluxestockscreen.aspx?query=Institutional+Ownership+Down+Last+Month" |sed 's/TR/\n/g' |egrep -o "Symbol=[A-Z]+" |cut -d= -f2 > InstitutionDownList

echo "Cheap Stocks"
curl -stderr "http://moneycentral.msn.com/investor/finder/deluxestockscreen.aspx?query=Cheapest+Stocks+of+Large%2C+Growing+Companies&btnQryFrm=Go" |sed 's/\<TR\>/\n/g' |egrep -o "Symbol=[A-Z]+" |cut -d= -f2 > CheapList

echo "Earning release next two days"
./earning.sh > EarningList

echo "Crammer's pump and dump"
export url="http://madmoney.thestreet.com/index.cfm?page=screener"
if [ `date +%u` == 1 ]
then #if Monday fetch last Friday
    export lasttrade=`date -d-3day +'%Y-%m-%d'`
else #else fetch the last Biz day
    export lasttrade=`date -d-1day +'%Y-%m-%d'`
fi
export submit="submit=Y&sector=%25&Industry=%25&called=%25&segment=%25&airdate=$lasttrade&change=%25&pricelow=0&pricehigh=500&sort=symbol&ad=ASC"
export return=`curl -stderr -d $submit $url`
echo $return |egrep -o ">[A-Z]{1,4}<" |sed -e 's/>//g' -e 's/<//g' > CrammerList

echo "MSN member's recommendation"
curl -stderr "http://moneycentral.msn.com/community/message/default.aspx" |egrep -e "symbol=[A-Z]{1,4}" | cut -d'>' -f3- |cut -d'<' -f1 |sort |uniq >MsnList

echo "SchaeffersResearch high call volume" # puts does not work for now
curl -stderr -d "lstVolume=calls" "http://www.schaeffersresearch.com/streetools/market_tools/unusually_high_option_volume.aspx" |egrep -o "ticker_symbol=[A-Z]{1,4}" |uniq|cut -d'=' -f2 > UnusualCallList

echo "schaeffer filters"
./schaefferscreen.sh

echo "Etrad recommendation"
./etrade-list.sh

echo "Three Month Trend from high to low"
curl -stderr "http://www.prophet.net/explore/sectorPerformance.jsp?sortBy=1172793600000&orderBy=-1&interval=7&showPercent=false&period=3m" |egrep "sectorid=" |egrep -o '>[A-Za-z ]+<' |sed -e 's/>//g' -e 's/<//g' |cat -n > ThreeMonthTrend

echo "Stock Picker"
./stockpickr.sh
./pickerpro.sh

#Yesterday's top performer's activity
./covestortop100.sh 1 
cat CovestorList |grep LONG  |cut -d',' -f2 > CovestorLongList
cat CovestorList |grep SHORT |cut -d',' -f2 > CovestorShortList
cat CovestorList |grep SOLD  |cut -d',' -f2 > CovestorSoldList

#--------------------Slow Process Starts----------------------------------
#TraderStar
./traderstars.sh & 

echo "MotleyFool Rating"
./motleyfool.sh &
#stock pick report
echo "Stoxline Rating"
./stoxline.sh &

echo "Stockreport Rating"
./stockpickreport.sh &

echo "Power Rating"
./powerrating.sh &

echo "Short Increase/Decrease List"
./shortsqueezeplay.sh &

echo "Trend Spotter Rating"
./trendspotter.sh  &
